{
  "properties" : { },
  "id" : "1b6c6dd122174ce98d0596b8893844d4",
  "script" : null,
  "groupId" : "ded0996d4aa14841ae2d40edb1fa6d63",
  "name" : "设备导入",
  "createTime" : 1727071139247,
  "updateTime" : 1726305740750,
  "lock" : "1",
  "createBy" : "ndmp",
  "updateBy" : "ndmp",
  "path" : "import",
  "method" : "POST",
  "parameters" : [ {
    "name" : "file",
    "value" : { },
    "description" : "",
    "required" : false,
    "dataType" : "MultipartFile",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  } ],
  "options" : [ ],
  "requestBody" : "",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"status\": 200,\n    \"message\": \"success\",\n    \"data\": {}\n}",
  "description" : "",
  "requestBodyDefinition" : {
    "name" : "",
    "value" : { },
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "status",
      "value" : "200",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "success",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
 import org.apache.poi.ss.usermodel.Workbook
 import org.apache.poi.hssf.usermodel.HSSFWorkbook
 import org.apache.poi.xssf.usermodel.XSSFWorkbook
 import org.apache.poi.ss.usermodel.Sheet

 import com.kd.ndmp.core.enums.DeviceTypeEnum
 import com.kd.ndmp.core.enums.PingEnableEnum
 import com.kd.ndmp.core.enums.DeviceFirmEnum
 import com.kd.ndmp.core.enums.StationTypeEnum
 import com.kd.ndmp.core.enums.StationPropEnum
 import com.kd.ndmp.core.enums.VoltageLevelEnum
 import com.kd.ndmp.core.enums.NetRegionEnum
 import com.kd.ndmp.core.enums.AccessNetworkEnum
 import com.kd.ndmp.util.IdUtil

 import java.io.InputStream

 InputStream inputStream = file.getInputStream(); //获取前端传递过来的文件对象，存储在“inputStream”中
 String fileName = file.getOriginalFilename(); //获取文件名

 Workbook workbook = null; //用于存储解析后的Excel文件

 //判断文件扩展名为“.xls还是xlsx的Excel文件”,因为不同扩展名的Excel所用到的解析方法不同
 String fileType = fileName.substring(fileName.lastIndexOf("."));
 if (".xls".equals(fileType)) {
     workbook = new HSSFWorkbook(inputStream); //HSSFWorkbook专门解析.xls文件
 } else if (".xlsx".equals(fileType)) {
     workbook = new XSSFWorkbook(inputStream); //XSSFWorkbook专门解析.xlsx文件
 }



 Sheet sheet = workbook.getSheetAt(0); //读取sheet 0

 int firstRowIndex = sheet.getFirstRowNum() + 1;
 int lastRowIndex = sheet.getLastRowNum() - 1;

 for (rIndex in range(firstRowIndex, lastRowIndex)) { //遍历行
     Row row = sheet.getRow(rIndex);
     if (row != null) {
         int firstCellIndex = row.getFirstCellNum();
         int lastCellIndex = row.getLastCellNum();

         Map mapCell = new HashMap();
         for (cIndex in range(firstCellIndex, lastCellIndex - 1)) { //遍历列

             Cell cell = row.getCell(cIndex);
             if (cell != null) {
                 mapCell.put(cell.getColumnIndex(), cell.toString())

             }

         }
         String deviceId = IdUtil.generateDeviceId(mapCell.get(10));
         db.table("ndmp_device").primary('id').insert({
             id: deviceId,
             net_region: NetRegionEnum.getValue(mapCell.get(0)),
             station_prop: StationPropEnum.getValue(mapCell.get(1)),
             station_type: StationTypeEnum.getValue(mapCell.get(2)),
             voltage_level: VoltageLevelEnum.getValue(mapCell.get(3)),
             dcc_id: mapCell.get(4),
             access_network: AccessNetworkEnum.getValue(mapCell.get(5)),
             sn_code: mapCell.get(6),
             device_name: mapCell.get(7),
             device_model_id: mapCell.get(8),
             device_type: DeviceTypeEnum.getValue(mapCell.get(9)),
             ip: mapCell.get(10),
             operate_date: mapCell.get(11)
         })

         db.table("ndmp_net_snmp_protocol").primary('id').insert({
             id: IdUtil.getSnowflakeNextId(),
             device_id: deviceId,
             snmp_version: mapCell.get(12),
             rocommunity: mapCell.get(13),
             rwcommunity: mapCell.get(14),
             port_rw: mapCell.get(15)::int

         })

         db.table("ndmp_net_device_protocol").primary('id').insert({
             id: IdUtil.getSnowflakeNextId(),
             device_id: deviceId,
             device_username: mapCell.get(16),
             device_password: mapCell.get(17),
             device_port: mapCell.get(18)::int

         })


     }
 }

 inputStream.close();